//
//  MYGCommunityQuestionInfoView.swift
//  MYGrow
//
//  Created by lance on 2024/3/3.
//

import UIKit

class MYGCommunityQuestionInfoView: UIView {
    // MARK: - Property
    var model: MYGCommunityDetailModel? {
        didSet {
            guard let model = model else { return }
            questionLabel.text = model.communities_patient?.title
            userInfoLabel.text = "\(model.communities_patient?.patient?.name ?? "")"
//            publishInfoLabel.text = "\(model.region ?? "") \(model.created_at?.components(separatedBy: " ").first ?? "")"
            headImageView.sd_setImage(with: URL(string: model.communities_patient?.patient?.avatar ?? ""), placeholderImage: headPlaceholderImage)
        }
        
    }
    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        addSubviews([
            questionIcon,
            questionLabel,
            headImageView,
            userInfoLabel,
            publishInfoLabel
        ])
        
        questionIcon.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.top.equalTo(20)
            make.size.equalTo(CGSize(width: 25, height: 25))
        }
        
        questionLabel.snp.makeConstraints { make in
            make.left.equalTo(questionIcon.snp.right).offset(8.5)
            make.top.equalTo(questionIcon.snp.top).offset(1.5)
            make.right.equalToSuperview().offset(-15)
            make.height.greaterThanOrEqualTo(22.5)
        }
        
        headImageView.snp.makeConstraints { make in
            make.top.equalTo(questionLabel.snp.bottom).offset(20)
            make.left.equalTo(15)
            make.size.equalTo(CGSize(width: 25, height: 25))
            make.bottom.equalTo(-20)
        }
        
        userInfoLabel.snp.makeConstraints { make in
            make.left.equalTo(headImageView.snp.right).offset(8.5)
            make.centerY.equalTo(headImageView)
        }
        
        publishInfoLabel.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-15)
            make.centerY.equalTo(headImageView)
        }
    }
    
    // MARK: - Public funcs
    
    // MARK: - lazy load
    private lazy var questionIcon: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "Community/question_icon"))
        return imageV
    }()
    
    private lazy var questionLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(16)
        label.textColor = .rgba(51, 51, 51)
        label.numberOfLines = 0
        return label
    }()
    
    private lazy var headImageView: UIImageView = {
        let imageV = UIImageView(image: headPlaceholderImage)
        imageV.contentMode = .scaleAspectFill
        imageV.layerCornerRadius = 12.5
        return imageV
    }()
    
    private lazy var userInfoLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(13)
        label.textColor = .rgba(93, 93, 93)
        return label
    }()
    
    private lazy var publishInfoLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(13)
        label.textColor = .rgba(93, 93, 93)
        return label
    }()
        
}
